/**
 * $id$
 */
package org.ishequ.miduo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ishequ.miduo.R;
import org.ishequ.miduo.renren.ApiItem;
import org.ishequ.miduo.renren.ApiItemGroup;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;

/**
 * APP List
 */
public class AppListActivity extends BaseActivity {

	private LinearLayout appListLayout;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		appListLayout = (LinearLayout) getLayoutInflater().inflate(
				R.layout.app_list, null);
		root.addView(appListLayout);
		initAppList();

		// 设置标题栏文字
		titlebarText.setText("选择应用");
	}

	/**
	 * Initialize the api list
	 */
	private void initAppList() {
		ArrayList<AppItemGroup> groups = new ArrayList<AppItemGroup>();
		// User info api group
		AppItemGroup appGroup = new AppItemGroup(
				getString(R.string.app_group));
		appGroup.addAppItem(new AppItem(getString(R.string.app_weibo),
				"","", R.drawable.weibo_logo_sm));
		appGroup.addAppItem(new AppItem(getString(R.string.app_renren),
				"","", R.drawable.renren_logo_s));
		appGroup.addAppItem(new AppItem(getString(R.string.app_qzone),
				"","", R.drawable.qzone_logo_s));
		appGroup.addAppItem(new AppItem(getString(R.string.app_t_qq),
				"","", R.drawable.tqq_logo_s));
		groups.add(appGroup);

		// add to api list
		AppListAdapter adapter = new AppListAdapter(this, groups);
		ListView appList = (ListView) appListLayout.findViewById(R.id.app_list);
		appList.setFadingEdgeLength(0);
		appList.setAdapter(adapter);
	}
}

class AppItemGroup {
	private String title;
	private ArrayList<AppItem> appItems;
	
	public AppItemGroup(String title) {
		this.title = title;
		this.appItems = new ArrayList<AppItem>();
	}
	
	public AppItemGroup(String title, ArrayList<AppItem> apiItems) {
		this.title = title;
		this.appItems = appItems;
	}
	
	public synchronized ArrayList<AppItem> addAppItem(AppItem appItem) {
		if(appItem != null) {
			appItems.add(appItem);
		}
		return appItems;
	}
	
	public String getTitle() {
		return title;
	}
	
	/**
	 * Get the app item list
	 * @return
	 */
	public final ArrayList<AppItem> getAppItems() {
		return appItems;
	}
}


class AppItem {
	
	private String label;
	
	private String name;
	/**
	 * The name for invoking
	 */
	public String invokeName;
	
	public int logoId;
	
	public String getLabel() {
		return label;
	}

	public String getName() {
		return name;
	}

	public String getInvokeName() {
		return invokeName;
	}

	public int getLogoId() {
		return logoId;
	}

	public AppItem(String label, String name, String invokeName, int logoId){
		this.label = label;
		this.name = name;
		this.invokeName = invokeName;
		this.logoId = logoId;
	}
}
